var consultCtrl  = new XFApp.client();
$.views.converters({
	askStatus : function(value) {
		if(!value){
			return "";
		}
		if(value.index==2){
			return "无效问题";
		}else if(value.index==5){
			return "已回答";
		}else{
			return "待回答";
		}
		return  "未知类型("+value+")";
	},
});
XFApp.client.prototype.consult = {
	successCode : "10000",
	page : null,
	hisPage : null,
	hisId : 0,
	cusPage : null,
	socreId : 0,
	urlItems : {
		queryByPageURL : basePath+"/userCenter/consulation/queryPage",
		delConsultURL : basePath+"/userCenter/consulation/delConsult",
		subScoreURL:basePath+"/userCenter/consulation/subScore",
	},
	
	queryPage : function(){
		_this = this;
		var params = {
			}
		$("#from_group input").each(function(){
			if(!!$(this).val()){
				params[$(this).attr("name")]=$(this).val();
			}
		});
		$("#from_group select").each(function(){
			if(!!$(this).val()){
				params[$(this).attr("name")]=$(this).val();
			}
		});
		if(!!_this.page){
			_this.page.page("remote",0,params);
		}else{
			_this.page = $("#page").page({
				pageSize : 10,
				remote: {
					url: _this.urlItems.queryByPageURL,
			        params: params, 
			        success: function (data, pageIndex) {
			        	if(data.code==_this.successCode){
			        		var pageResult = data.result;
			        		if(pageResult.itemList.length>0){
			        			$("#page_grid").html($("#dataTmp").render(pageResult.itemList));
			        		}else{
			        			$("#page_grid").html('<tr><td align="center" colspan="14">暂无数据</td></tr>');
			        		}
			        	}else{
			        		  webDialogUtil.simpleAlert("数据查询失败", "温馨提示");
			        	}
			        },
			        error : function(){
			        	webDialogUtil.simpleAlert("数据查询失败", "温馨提示");
			        }
				},
				firstBtnText : '首页',
				lastBtnText : '尾页',
				prevBtnText : '上一页',
				nextBtnText : '下一页',
				showInfo : true,
				showJump : true,
				jumpBtnText : '跳转',
				showPageSizes : true,
				infoFormat : '共{pageCount}页,{total}项'
			});
		}
	},
	delConsult : function(id){
		_this = this;
		webDialogUtil.simpleConfrimAlert("是否确认删除", function(){
			$.ajax({
				url : _this.urlItems.delConsultURL,
				dataType : 'json',
				data  : {id:id},
				type : 'post',
				success : function(data) {
					if(data.code!=10000){
						webDialogUtil.simpleAlert(data.msg, "温馨提示");
					}else{
						webDialogUtil.simpleAlert("处理成功", "温馨提示");
						_this.queryPage();
					}
				}
			});
		}, null, "温馨提示");
	},
	clk_check : function(){
		if(!!$("#check_all").prop("checked")){
			$("[id^=checkbox_]").prop("checked","checked");
		}else{
			$("[id^=checkbox_]").prop("checked","");
		}
	},
	
	gradeModal : function(id){
		this.socreId = id;
		$("#grade_modal").modal('show');
	},
	subScore : function(){
		var _this = this;
		webDialogUtil.simpleConfrimAlert("是否确认打分", function(){
			$.ajax({
				url : _this.urlItems.subScoreURL,
				dataType : 'json',
				data  : {id:_this.socreId,grade:$("#gradeSelect").val()},
				type : 'post',
				success : function(data) {
					if(data.code!=10000){
						webDialogUtil.simpleAlert(data.msg, "温馨提示");
					}else{
						webDialogUtil.simpleAlert("处理成功", "温馨提示");
						$("#grade_modal").modal('hide');
						_this.queryPage();
					}
				}
			});
		}, null, "温馨提示");
	},
	event : function(){
		_this = this;
		$("#consulation_search").on("click",function(){
			_this.queryPage();
		});
		$("#consulation_reset").on("click",function(){
			$("form").each(function() {   
				   this.reset();   
			});
			$("select").val("");
		});
		$("#gradeBtn").on("click",function(){
			_this.subScore();
		});
		
		$("#check_all").on("click",function(){
			_this.clk_check();
		});
		
		$("select[name='department']").on("change",function(){
			var content = '<option value="">全部</option>';
			if(!!$(this).val()){
				$("select[name='department']").find("option[name='industry"+$(this).val()+"']").each(function(){
					var box = $('<div></div>');
					var sel = $(this).clone();
					sel.css("display","");
					box.append(sel);
					content+=box.html();
				});
				$("select[name='industryClassify']").html(content);
			}else{
				$("select[name='industryClassify']").html(content);
				$("select[name='industryClassify']").val("");
			}
		});
	},
};
$(function(){
	consultCtrl.consult.event();
	consultCtrl.consult.queryPage();
});